﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AntdUI;
namespace TPressure
{
    public partial class SelectTemplateForm : BaseForm
    {
        #region
        /// <summary> 类型 1-编辑工程进入
        /// 
        /// </summary>
        public int type;
        #endregion

        #region 自定义方法

        /// <summary>设备列表
        /// 
        /// </summary>
        public void LoadTemplateList()
        {
            List<Template> list = SqlSugarHelper.Inquireable<Template>(null);
            UpdateTable(list);
        }

        /// <summary>更新DataGridView
        /// 
        /// </summary>
        /// <param name="list"></param>
        private void UpdateTable(List<Template> list)
        {
            var antItemList = new List<TemplateItem>();
            foreach (Template item in list)
            {
                string first = string.Format("压力:{0}--时长：{1}", item.first_stage_pressure.ToString(), item.first_stage_minute.ToString());
                string second = string.Format("压力:{0}--时长：{1}", item.second_stage_pressure.ToString(), item.second_stage_minute.ToString());
                string third = string.Format("压力:{0}--时长：{1}", item.third_stage_pressure.ToString(), item.third_stage_minute.ToString());
                string rigor = string.Format("压力:{0}--时长：{1}", item.rigor_stage_pressure.ToString(), item.rigor_stage_minute.ToString());
                string intensity = string.Format("压力:{0}--时长：{1}", item.intensity_stage_pressure.ToString(), item.intensity_stage_minute.ToString());
                string edit = "否";
                if (item.edit_enable == 1)
                {
                    edit = "是";
                }
                antItemList.Add(new TemplateItem(item.template_number, item.pipe_position, item.design_pressure,
                    first, second, third, rigor, intensity, edit));
            }
            Table1.DataSource = antItemList;
        }

        #endregion

        public SelectTemplateForm()
        {
            InitializeComponent();
        }

        private void SelectTemplateForm_Load(object sender, EventArgs e)
        {
            Table1.Columns = new AntdUI.ColumnCollection {
                new AntdUI.Column("template_number","模板编号"){ColAlign=AntdUI.ColumnAlign.Center},
                new AntdUI.Column("pipe_position","管道位置"){ColAlign=AntdUI.ColumnAlign.Center},
                new AntdUI.Column("design_pressure","设计压力"){ColAlign=AntdUI.ColumnAlign.Center},
                new AntdUI.Column("first_stage","第一阶段"){ColAlign=AntdUI.ColumnAlign.Center},
                new AntdUI.Column("second_stage","第二阶段"){ColAlign=AntdUI.ColumnAlign.Center},
                new AntdUI.Column("third_stage","第三阶段"){ColAlign=AntdUI.ColumnAlign.Center},
                new AntdUI.Column("rigor_stage","严密阶段"){ColAlign=AntdUI.ColumnAlign.Center},
                new AntdUI.Column("intensity_stage","强度阶段"){ColAlign=AntdUI.ColumnAlign.Center},
            };
            Spin.Config config = new Spin.Config
            {
                Text = "正在加载中...",
            };
            Table1.Spin(config, () =>
            {
                LoadTemplateList();
            }, () =>
            {

            });
        }

        private void Table1_CellDoubleClick(object sender, TableClickEventArgs e)
        {
            TemplateItem item = (TemplateItem)e.Record;
            if (type == 1)
            {
                EditProjectForm frm = (EditProjectForm)this.Owner;
                frm.templateObj = item;
                frm.freshTemplateInfo();
            }
            else
            {
                AddProjectForm frm = (AddProjectForm)this.Owner;
                frm.templateObj = item;
                frm.freshTemplateInfo();
            }
            this.Close();
        }
    }
}
